package com.stylefeng.guns.modular.system.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.util.Query;
import com.stylefeng.guns.modular.system.model.CmsAllAuthInfo;
import com.stylefeng.guns.modular.system.service.IUserService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.ui.Model;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.modular.system.model.CmsAuthInfo;
import com.stylefeng.guns.modular.system.service.ICmsAuthInfoService;

import java.util.Map;

/**
 * 控制器
 *
 * @author fengshuonan
 * @Date 2018-10-22 16:58:38
 */
@Controller
@RequestMapping("/cmsAuthInfo")
public class CmsAuthInfoController extends BaseController {

    private String PREFIX = "/system/cmsAuthInfo/";

    @Autowired
    private ICmsAuthInfoService cmsAuthInfoService;
    @Autowired
    private IUserService userService;

    /**
     * 跳转到首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "cmsAuthInfo.html";
    }

    /**
     * 跳转到添加
     */
    @RequestMapping("/cmsAuthInfo_add")
    public String cmsAuthInfoAdd() {
        return PREFIX + "cmsAuthInfo_add.html";
    }

    /**
     * 跳转到修改
     */
    @RequestMapping("/cmsAuthInfo_update/{cmsAuthInfoId}")
    public String cmsAuthInfoUpdate(@PathVariable Long cmsAuthInfoId, Model model) {
        Map<String,Object> map = cmsAuthInfoService.getInfoByUserId(cmsAuthInfoId);
        model.addAttribute("item",map);
        LogObjectHolder.me().set(map);
        return PREFIX + "cmsAuthInfo_edit.html";
    }

    /**
     * 获取列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(@RequestParam Map<String,Object> params) {
        Query query = new Query(params);
        return cmsAuthInfoService.getAllInfo(params);
    }
    
    /**
     * 获取列表
     */
    @RequestMapping(value = "/getOne")
    @ResponseBody
    public Object getOne(@RequestParam Map<String,Object> params) {
        return cmsAuthInfoService.getInfoByUserId(Long.parseLong(params.get("id").toString()));
    }
    
    

    /**
     * 新增
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(CmsAuthInfo cmsAuthInfo) {
        cmsAuthInfoService.insert(cmsAuthInfo);
        return SUCCESS_TIP;
    }

    /**
     * 删除
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer cmsAuthInfoId) {
        cmsAuthInfoService.deleteById(cmsAuthInfoId);
        return SUCCESS_TIP;
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(CmsAllAuthInfo cmsAllAuthInfo) {
        if(StringUtils.isBlank(cmsAllAuthInfo.getDemandDetail())){
            throw new RuntimeException();
        }
        cmsAuthInfoService.updateCmsAuthInfo(cmsAllAuthInfo);
        return SUCCESS_TIP;
    }

    /**
     * 详情
     */
    @RequestMapping(value = "/detail/{cmsAuthInfoId}")
    @ResponseBody
    public Object detail(@PathVariable("cmsAuthInfoId") Integer cmsAuthInfoId) {
        return cmsAuthInfoService.selectById(cmsAuthInfoId);
    }

    /**
     * 跳转到详情;跳转到更新;
     */
    @RequestMapping("/cmsAuthInfo_pages/{cmsAuthInfoId}")
    public String cmsAuthInfoDetail(@PathVariable("cmsAuthInfoId") Integer cmsAuthInfoId) {
        return PREFIX + "cmsAuthInfo_detail.html";
    }
}
